package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.ContractVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/nursing_project")
@Api(tags = "护理项目")
public class NursingProjectController extends BaseController{
    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 分页查询
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping
    @ApiOperation("分页护理项目")
    public ResponseResult<PageResponse<NursingProjectVo>> selectPage(@ApiParam(value ="护理项目名称") String name,
                                                                     @ApiParam(value ="当前页") @RequestParam(defaultValue ="1") Integer pageNum,
                                                                     @ApiParam(value ="每页显示记录数") @RequestParam(defaultValue ="10")Integer pageSize,
                                                                     @ApiParam(value = "状态") Integer status){
        System.out.println("=============================================================================");
        System.out.println(pageNum);
        System.out.println(pageSize);
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.getByPage(name,status,pageNum,pageSize);
        return success(pageResponse);
    }

    /**
     * 新增护理项目
     * @param nursingProjectDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(
            @ApiParam(value = "护理项目数据传输对象", required = true)
            @RequestBody NursingProjectDto nursingProjectDTO) {
        nursingProjectService.add(nursingProjectDTO);
        return ResponseResult.success();
    }
    /**
     * 根据id查询
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> getById(
            @PathVariable("id") Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return ResponseResult.success(nursingProjectVo);
    }
    /**
     * 修改护理项目
     */
    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult update (@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.update(nursingProjectDto);
        return ResponseResult.success();
    }

    /**
     * 删除护理项目
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult delete (@PathVariable("id") Long id){
        nursingProjectService.delete(id);
        return ResponseResult.success();
    }

    /**
     * 启用禁用
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用和禁用")
    public ResponseResult updateStatus(@PathVariable("id") Long id,@PathVariable("status") int status){
        nursingProjectService.updateStatus(id,status);
        return ResponseResult.success();
    }
    /**
     * 查询所有项目
     */
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult <NursingProject> selectAll(){
        List<NursingProject> list = nursingProjectService.selectAll();
        return ResponseResult.success(list);
    }
}
